package com.gdssoft.pdaweb;

import java.util.Calendar;

import javax.annotation.Resource;

import com.gdssoft.BaseTestCase;
import com.gdssoft.core.util.DateUtil;
import com.gdssoft.pdaweb.model.CrmWorkOrder;
import com.gdssoft.pdaweb.model.am.PdaAmMeter;
import com.gdssoft.pdaweb.model.am.PdaAmMeterList;
import com.gdssoft.pdaweb.model.water.PdaWaterList;
import com.gdssoft.pdaweb.model.water.PdaWaterMeter;
import com.gdssoft.pdaweb.service.CrmService;

public class CrmServiceTestCase extends BaseTestCase {
	@Resource
	private CrmService crmService;
	
	public void testSyncWordOrderStatus() {
		try {
			CrmWorkOrder crmWorkOrder = new CrmWorkOrder();
			crmWorkOrder.setActivityUID("1-1LG98O");
			crmWorkOrder.setWorkStatus("已完成");    //接口文檔要改,說明清楚
			crmWorkOrder.setPlannedCompletion(Calendar.getInstance().getTime());
			crmWorkOrder.setComment("测试完成的订单");
			System.out.println(crmService.syncWordOrderStatus(crmWorkOrder));
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void testPushWaterMeter() {
		/*
		 * 推送的水表結構
		 * 6922868285730
		 * |--6922868285731
		 * |--6922868285732
		 */
		try {
			PdaWaterMeter pdaWaterMeter = new PdaWaterMeter();
			
			pdaWaterMeter.setAparmentId("111611021010402");  //房屋在CRM中要存在
			pdaWaterMeter.setAmId("6922868285733");
			pdaWaterMeter.setMeterKind("住宅");  // 限制字段,接口文檔要說明清楚
			pdaWaterMeter.setIndoor("0");
			pdaWaterMeter.setIsCharge("0");
			pdaWaterMeter.setType("使用中");    // 限制字段,接口文檔要說明清楚
			pdaWaterMeter.setTimesNum(1);
			pdaWaterMeter.setUpId("");  // 目前推上下級表不會出錯,但CRM未建立關係
			
			System.out.println(crmService.pushWaterMeter(pdaWaterMeter));
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void testPushWaterRecord() {
		try {
			PdaWaterList pdaWaterList = new PdaWaterList();
			//推上月数据
			pdaWaterList.setAmId("6922868285733");
			Calendar cal = Calendar.getInstance();
			cal.add(Calendar.MONTH, -1);
			pdaWaterList.setRecordTime(cal.getTime());
			pdaWaterList.setDegree(4500L);
			pdaWaterList.setLastDegree(3000L);
			pdaWaterList.setFixedUsage(0L);
			pdaWaterList.setComments("测试推送水表读数");
			
			System.out.println(pdaWaterList.getRecordTime());
			System.out.println("push PdaWaterList : " + crmService.pushWaterRecord(pdaWaterList));
			
			//推当月数据
			PdaWaterList pdaWaterList2 = new PdaWaterList();
			
			pdaWaterList2.setAmId("6922868285733");
			pdaWaterList2.setRecordTime(Calendar.getInstance().getTime());
			pdaWaterList2.setDegree(300L);
			pdaWaterList2.setLastDegree(4500L);
			pdaWaterList2.setFixedUsage(5000L);
			pdaWaterList2.setComments("测试推送水表读数，換表，修正5000度");
			
			System.out.println(pdaWaterList2.getRecordTime());
			System.out.println("push PdaWaterList2 : " + crmService.pushWaterRecord(pdaWaterList2));
			
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void testPushAmMeter() {
		/*
		 * 6947503700233 屋內不計費,1倍率
		 * 6947503700234 非屋內計費,10倍率
		 */
		try {
			PdaAmMeter pdaAmMeter = new PdaAmMeter();
			
			pdaAmMeter.setAparmentId("111611021010402");
			pdaAmMeter.setAmId("6947503700234");
			pdaAmMeter.setMeterKind("住宅");
			pdaAmMeter.setIndoor("1");
			pdaAmMeter.setIsCharge("0");
			pdaAmMeter.setType("使用中");
			pdaAmMeter.setTimesNum(10);
			pdaAmMeter.setUpId("");
			
			System.out.println(crmService.pushAmMeter(pdaAmMeter));
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public void testPushAmRecord() {
		try {
			PdaAmMeterList pdaAmMeterList = new PdaAmMeterList();
			//推上月数据
			pdaAmMeterList.setAmId("6947503700232");
			Calendar cal = Calendar.getInstance();
			cal.add(Calendar.MONTH, -1);
			pdaAmMeterList.setRecordtime(cal.getTime());
			pdaAmMeterList.setDegree(100L);
			pdaAmMeterList.setLastDegree(50L);
			pdaAmMeterList.setFixedUsage(0L);
			pdaAmMeterList.setComments("测试推送电表读数");
			
			System.out.println("push pdaAmMeterList : " + crmService.pushAmRecord(pdaAmMeterList));
			
			//推当月数据
			PdaAmMeterList pdaAmMeterList2 = new PdaAmMeterList();
			
			pdaAmMeterList2.setAmId("6922868285730");
			pdaAmMeterList2.setRecordtime(Calendar.getInstance().getTime());
			pdaAmMeterList2.setDegree(200L);
			pdaAmMeterList2.setLastDegree(100L);
			pdaAmMeterList2.setFixedUsage(8L);
			pdaAmMeterList2.setComments("测试推送水表读数，修正8度");
			
			System.out.println("push pdaAmMeterList2 : " + crmService.pushAmRecord(pdaAmMeterList2));
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
		
